package com.duan.laugh.starter.email;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * jdbc的邮箱账户初始化到存储器里
 *
 * @author duanjw
 */
public class InitJdbcEmailAccount2Repository {
    private final static String SELECT_ACCESS_SQL = "SELECT * FROM EMAIL_ACCOUNT";
    private JdbcTemplate jdbcTemplate;

    public InitJdbcEmailAccount2Repository(DataSource dataSource, EmailAccountRepository emailAccountDefinitionRepository) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
        jdbcTemplate.query(SELECT_ACCESS_SQL, new BeanPropertyRowMapper<>(EmailAccount.class)).forEach(item -> emailAccountDefinitionRepository.add(item));
    }
}
